/*
 * @Author: tanjunyi@doctorwork.com
 * @Date: 2020-04-08 18:10:21
 * @LastEditors: tanjunyi@doctorwork.com
 * @LastEditTime: 2020-04-08 23:06:01
 * @Description:
 */
class myPlugin {
	constructor(options) {
		console.log("----- myPlugin options:", options)
	}

	apply(compiler) {
		compiler.plugin('compilation', (compilation, callback) => {
			console.log("---------- my Plugin, this.is  compilation", compilation)
			// 在生成文件中，创建一个头部字符串：
			var filelist = 'In this build:\n\n';
			for (var filename in compilation.assets) {
				filelist += ('- ' + filename + '\n');
			}

			// 将这个列表作为一个新的文件资源，插入到 webpack 构建中：
			compilation.assets['filelist.md'] = {
				source: function () {
					return filelist;
				},
				size: function () {
					return filelist.length;
				}
			};

		})
	}
}

module.exports = myPlugin;